
/**
 * Project Name:cats-core
 * File Name:TreeEntity.java
 * Package Name:com.catsic.core.entity.base
 * Date:2014年5月8日上午11:11:15
 * Copyright (c) 2014, oa.catsic.com All Rights Reserved.
 */
 
package com.catsic.base.tree;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Where;

import com.catsic.base.BaseEntity;
import com.catsic.base.status.Status;

/**
 * ClassName: TreeEntity
 * Description: 树的基本类
 * date: 2014年5月8日 上午11:11:15
 * author: yangyd
 */
@MappedSuperclass
public class TreeImpl<T> extends BaseEntity implements Tree<T>{
	/**
	 * 节点名称
	 */
	@Column(name="NAME",nullable=false)
	private String name;
	
	/**
	 * 父节点
	 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "PID")
	private T parent;
	
	/**
	 * 子节点
	 */
	@OneToMany(fetch = FetchType.LAZY ,cascade = CascadeType.REMOVE, mappedBy = "parent")
	@OrderBy("code ASC")
	@Where(clause = "status='有效'")
	@Cache (usage = CacheConcurrencyStrategy.READ_WRITE)  
	private List<T> childs;
	
	/**
	 * CODE:编码
	 */
	@Column(name = "CODE",nullable = false, unique = true)
	private String code;
	
	/**
	 * status:节点状态
	 */
	@Column(name="STATUS",nullable=false)
	@Enumerated(EnumType.STRING)
	private Status status = Status.有效;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public T getParent() {
		return parent;
	}

	public void setParent(T parent) {
		this.parent = parent;
	}

	public List<T> getChilds() {
		return childs;
	}

	public void setChilds(List<T> childs) {
		this.childs = childs;
	}
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}
}
